/**
 * Created by win7 on 2017/3/14.
 */
import React from "react";
import "./css/OrderTable.css";
import Util from "../../util/Util";
import Pagination from "./Pagination";
import {hashHistory} from "react-router";
/*信息列表*/


export default class OrderTable extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            orders: [],
            total: 0
        }
        this.orderstatecp = {
            0: "待发布",
            1: "已发布",
            2: "已接单",
            3: "已签订",
            4: "已完成",
        };
        this.ordertypecp = {
            1: "成衣订单",
            2: "辅料订单",
            3: "布料订单",
            4: "印染订单",
            5: "纱线订单",
        }

    }


    jumptree(oid) {
        hashHistory.push({pathname: '/ordertree/', state: {'oid': oid}})
    }

    searchTree(oid) {
        hashHistory.push("/orderTree/" + oid);
    }

    componentWillMount() {

    }

    jumpOrderDetil(oty,oid){
        // debugger
        // switch (oty){
        //     case 0:
        //         return;
        //     case 1:
        //         // hashHistory.push('/orderdetailgms/'+oid);
        //         // hashHistory.push({pathname:'/orderdetailgms/',state:{'oid':oid}})
        //         return;
        //     case 2:
        //         hashHistory.push('/orderdetailraw/'+oid);
        //         // hashHistory.push({pathname:'/orderdetailraw/',state:{'oid':oid}})
        //         return;
        //     case 3:
        //         hashHistory.push('/orderdetailcloth/'+oid);
        //         // hashHistory.push({pathname:'/orderdetailcloth/',state:{'oid':oid}})
        //         return;
        //     case 4:
        //         hashHistory.push('/orderdetailprint/'+oid);
        //         // hashHistory.push({pathname:'/orderdetailprint/',state:{'oid':oid}})
        //         return;
        //     case 5:
        //         hashHistory.push('/orderdetailyarn/'+oid);
        //         // hashHistory.push({pathname:'/orderdetailprint/',state:{'oid':oid}})
        //         return;
        //
        // }
        let record = {};
        record.oid = oid;
        record.enId = '0';
        hashHistory.push({pathname:'/OrderIndex/',state:{defaultActiveKey: '1','record':record}});
    }

    addItem() {
        return this.props.orders.map((context, index) => {
            let date = Util.dateFormat(context.createDate);
            let state = this.orderstatecp[context.status];
            let type = this.ordertypecp[context.orderType];
            return <tr key={index}>
                <td>{date}</td>
                <td>
                    <a  onClick={this.jumptree.bind(this, context.oid)}>
                        {context.oid}
                    </a>
                </td>
                <td>{context.partAName}</td>
                <td>{context.partBName}</td>
                <td>{type}</td>
                <td>{state}</td>
                <td>{context.account/100}</td>
                <td>
                    <a onClick={this.jumpOrderDetil.bind(this, context.orderType, context.oid)}>查看</a>
                </td>
            </tr>
        })
    }


    onSure(size, num) {
        let oid = '';
        if (this.props.orders.length == 1 && this.refs.pagination.state.dataSize == 1) {
            oid = this.props.orders[0].oid;
            this.refs.pagination.setState({
                text: 1
            })
        }

        this.props.requestdata(size, num, oid);
    }


    render() {
        return (
            <div className="order_list clear">
                {/*<ul>*/}
                    {/*<li className="orderManage_li" style={{backgroundColor: '#f2f2f2'}}>*/}
                        {/*<div className="orderManage_all orderManage_title1">下单时间</div>*/}
                        {/*<span className="orderManage_title2">订单编号</span>*/}
                        {/*<span className="orderManage_title3">甲方</span>*/}
                        {/*<span className="orderManage_title4">乙方</span>*/}
                        {/*<span className="orderManage_title5">订单类型</span>*/}
                        {/*<span className="orderManage_title6">订单状态</span>*/}
                        {/*<span className="orderManage_title7">订单金额(元)</span>*/}
                        {/*<span className="orderManage_title8">操作</span>*/}
                    {/*</li>*/}
                    {/*{*/}
                        {/*this.addItem()*/}
                    {/*}*/}
                {/*</ul>*/}

                <table className="settle_rec_table order_manage_table">
                    <thead>
                        <tr>
                            <th> 下单时间 </th>
                            <th>订单编号</th>
                            <th>甲方</th>
                            <th>乙方</th>
                            <th>订单类型</th>
                            <th>订单状态</th>
                            <th>订单金额(元)</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {
                            this.addItem()
                        }
                    </tbody>
                </table>
                {/*页码*/}
                <Pagination eachSize={10} dataSize={this.state.total} onSure={this.onSure.bind(this)}
                            ref={'pagination'}/>
            </div>
        )
    }
}
